//
//  QDDutyInspectorApplyViewController.m
//  QDMetroClient
//
//  Created by andi911 on 2019/5/31.
//  Copyright © 2019 YueWen. All rights reserved.
//

#import "QDDutyInspectorApplyViewController.h"
#import "QDMetroClient-Swift.h"

@interface QDDutyInspectorApplyViewController ()
//
@property (nonatomic,strong) UILabel *contentLab;
//
@property (nonatomic,strong) UIScrollView *scrollView;

@end

@implementation QDDutyInspectorApplyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"义务监督员申请";
    [self loadSetUpUI];
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    __weak __typeof(self)weakSelf = self;
    [self showHudInView:self.view  hint:@"正在加载..."];
    [QDNetworkingManager requestPostUrlString:@"supervisorApply/searchStatus" Parameters:dict success:^(NSURLSessionDataTask * _Nonnull dataTask, NSDictionary * _Nonnull data) {
        [self hideHud];
        if (![[data valueForKey:@"respcod"] isEqualToString:@"01"]) {
            [self showHint:data[@"respmsg"]];
        }else{
            NSDictionary *protocol = data[@"data"][@"protocol"];
            weakSelf.navigationItem.title = protocol[@"title"];
            weakSelf.contentLab.text = protocol[@"contents"];
            CGFloat heihgt = [weakSelf.contentLab.text cly_stringHeightWithFont:CLYFont(16) width:Screen_W-40];
            weakSelf.contentLab.height = heihgt;
            weakSelf.scrollView.contentSize = CGSizeMake(Screen_W, weakSelf.contentLab.bottom);
        }
    } failure:^(NSURLSessionDataTask * _Nonnull dataTask, NSError * _Nonnull error) {
        [self hideHud];
        [self showHint:@"网络请求失败"];
    }];
    
}


- (void)loadSetUpUI{
    [self.view addSubview:self.scrollView];
    [self.scrollView addSubview:self.contentLab];
    NSString *contentStr = @"";
    self.contentLab.text = contentStr;
    CGFloat heihgt = [self.contentLab.text cly_stringHeightWithFont:CLYFont(16) width:Screen_W-40];
    self.contentLab.height = heihgt;
    self.contentLab.center = CGPointMake(Screen_W/2, 20+_contentLab.height/2);
    
    UIButton *bottomBtn = [[UIButton alloc]init];
    bottomBtn.width = Screen_W - 40;
    bottomBtn.height = 44;
    bottomBtn.layer.cornerRadius = 22;
    bottomBtn.layer.masksToBounds = YES;
    bottomBtn.backgroundColor = MainBtnColor;
    [bottomBtn setTitle:@"我要申请" forState:0];
    [bottomBtn addTarget:self action:@selector(tapApplyBtn) forControlEvents:1<<6];
    bottomBtn.center =  CGPointMake(Screen_W/2, Screen_H-88+bottomBtn.height/2+20);
    [self.view addSubview:bottomBtn];
}

- (void)tapApplyBtn{
    DLog(@"我要申请");
}


- (UILabel *)contentLab{
    if (!_contentLab) {
        UILabel *tempLab = [[UILabel alloc]init];
        tempLab.numberOfLines = 0;
        tempLab.width = Screen_W - 40;
        tempLab.height = 100;
        tempLab.font = CLYFont(16);
        tempLab.center = CGPointMake(Screen_W/2, 20+tempLab.height/2);
        _contentLab = tempLab;
    }
    return _contentLab;
}

- (UIScrollView *)scrollView{
    if(!_scrollView){
        UIScrollView *tempScrollView = [[UIScrollView alloc]init];
        tempScrollView.width = Screen_W;
        tempScrollView.height = Screen_H-(getRectNavAndStatusHight)-40-44;
        tempScrollView.center = CGPointMake(Screen_W/2, getRectNavAndStatusHight+tempScrollView.height/2);
        tempScrollView.scrollEnabled = YES;
//        tempScrollView.backgroundColor = [UIColor grayColor];
        //        tempScrollView.contentSize = CGSizeMake(Screen_W, Screen_H-getRectNavAndStatusHight-40-44-100);
        _scrollView = tempScrollView;
    }
    return _scrollView;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
